{% macro render_pagination(pagination) %}
    <div class="pagination">
        <div class="left">
            <label class="status status-info">共{{ pagination.total }}条记录,每页{{ pagination.per_page }}条</label>
        </div>
        <div class="right">
            {% for page in pagination.iter_pages() %}
                {% if page %}
                    {% if pagination.page == page %}
                        <button class="btn btn-mini btn-info active">{{ page }}</button>
                    {% else %}
                        <a href="{{ url_for(request.endpoint, page=page) }}">
                            <button class="btn btn-mini btn-info">{{ page }}</button>
                        </a>
                    {% endif %}
                {% else %}
                    <button class="btn btn-mini btn-info">...</button>
                {% endif %}
            {% endfor %}
        </div>
    </div>
{% endmacro %}

{% macro  render_pagination_for_sql(pagination) %}
    <div class="pagination">
        <div class="left">
            <label class="status status-info">共{{ pagination.total }}条记录,每页{{ pagination.per_page }}条</label>
        </div>
        <div class="right">
            {% for page in pagination.iter_pages %}
                {% if page %}
                    {% if pagination.page == page %}
                        <button class="btn btn-mini btn-info active">{{ page }}</button>
                    {% else %}
                        <a href="{{ url_for(request.endpoint, page=page) }}">
                            <button class="btn btn-mini btn-info">{{ page }}</button>
                        </a>
                    {% endif %}
                {% else %}
                    <button class="btn btn-mini btn-info">...</button>
                {% endif %}
            {% endfor %}
        </div>
    </div>
{% endmacro %}

{% macro render_field(field) %}
    <div class="form-row">
        <div class="label">{{ field.label.text }}<br>
        <small>({{ field.description }})</small>
        </div>
        <div class="input">
            {% if field.type == 'RadioField' %}
                {% for subfield in field %}
                    {{ subfield }}
                    {{ subfield.label }}
                {% endfor %}
            {% else %}
                {% if field.widget.input_type == 'text' %}
                    <i class="icon-ticket"></i>
                {% elif field.widget.input_type == 'password' %}
                    <i class="icon-key"></i>
                {% endif %}
                {% if field.name == 'target_month' %}
                    {{ field(class="icon large", placeholder=field.label.text,type='month') }}
                {% else %}
                    {{ field(class="icon large", placeholder=field.label.text) }}
                {% endif %}
            {% endif %}
            <span style="color: red;">{{ field.errors[0] }}</span>
        </div>
    </div>
{% endmacro %}

{% macro render_form(form) %}
    <form method="post">
        {{ form.hidden_tag() }}
        {% if caller %}
            {{ caller() }}
        {% else %}
            {% for id, field in form._fields.items() %}
                {% if field.widget.input_type != 'hidden' %}
                    {{ render_field(field) }}
                {% endif %}
            {% endfor %}
        {% endif %}

        <div class="form-button-bar">
            <button class="btn btn-default btn-small" type="reset"><i class="icon-refresh"></i> 重置</button>&nbsp;
            <button class="btn btn-success btn-small" id="submit" type="submit"><i class="icon-external-link"></i> 提交
            </button>
        </div>
    </form>
{% endmacro %}

{% macro render_add_user_form(form) %}
    <form method="post">
        {{ form.hidden_tag() }}
        {% if caller %}
            {{ caller() }}
        {% else %}
            {% for id, field in form._fields.items() %}
                {% if field.widget.input_type != 'hidden' %}
                    {{ render_field(field) }}
                {% endif %}
            {% endfor %}
        {% endif %}

        <div class="form-button-bar">
            <button class="btn btn-success btn-small" type="reset"><i class="icon-refresh"></i> 重置</button>
            <button class="btn btn-success btn-small" id="submit" type="submit"><i class="icon-external-link"></i> 提交
            </button>
        </div>
    </form>
{% endmacro %}

